// spawner.txt - Only exists to create creatures. Never moves or attacks. 
// If it sees a foe, it summons a creature. Does so at most once every 3 rounds.
// Cells 0 - 3 - Numbers of creatures to spawn. if 0, no use. GIVE THE IN-GAME NUMBER
// Cell 4,5 - Stuff done flag to set when spawner is killed. If both are 0, no flag set.

begincreaturescript;

variables;

short r1;
short last_spawn;
//short first_spawned = 0;
//short second_spawned = 0;
//short third_spawned = 0;
//short fourth_spawned = 0;
short need_to_inc_flag;

body;

beginstate INIT_STATE;
	last_spawn = get_current_tick();
	break;

beginstate DEAD_STATE;
	if ((get_memory_cell(4) != 0) || (get_memory_cell(5) != 0))
		inc_flag(get_memory_cell(4),get_memory_cell(5),1);
break;

beginstate START_STATE; 
	// see if target is visible
	get_foe_target(ME,8,0);
	
	if ((target_ok()) || (who_shot_me() >= 0)) {
		if (((tick_difference(last_spawn,get_current_tick()) > 1) ||
		  ((tick_difference(last_spawn,get_current_tick()) > 0) && (friends_nearby(6) == 0)))
		  && (get_attitude(ME) >= 10)) {
			r1 = get_ran(1,0,3);
			if (get_memory_cell(r1) > 0) {
				if (summon_creature(get_memory_cell(r1) - 8)) {
					print_str("The spawner makes a new creation!");
					set_summon_level(get_memory_cell(r1),1);
					//place_particle_num(get_memory_cell(r1),1,1,8);
					place_particle_num(get_memory_cell(r1),10,7,10);
					run_char_animation(2,1,50);	
					pc_heard_sound_delay(136,100);						
					
					last_spawn = get_current_tick();
					
					end();
					}
				}
			}
		}
	
break;

beginstate TALKING_STATE;
	print_str("A spawner is basically a big fungus. It can't communicate at all.");
break;
